<template>
	<view class="container">
		<u-number-box v-model="currentValue" :asyncChange="asyncChange" inputWidth="90rpx" bgColor="#fff"
			@change="handleChange">
			<view slot="minus" class="icon icon--bd-right" hover-class="icon--hover" hover-stay-time="150">
				-
			</view>
			<view slot="plus" class="icon icon--bd-left" hover-class="icon--hover" hover-stay-time="150">
				+
			</view>
		</u-number-box>
	</view>
</template>

<script>
	export default {
		name: "NumberBox",
		props: {
			value: {
				type: [String, Number],
				default: 0 || ''
			},
			asyncChange: {
				type: Boolean,
				default: true
			}
		},
		emits: ['input', 'change'],
		watch: {
			value: {
				handler(nVal) {
					this.currentValue = nVal
				},
				immediate: true,
			}
		},
		data() {
			return {
				// 输入框实际操作的值
				currentValue: '',
			};
		},
		methods: {
			handleChange(e) {
				this.$emit('input', e.value)
				this.$emit('change', e)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		box-sizing: border-box;
		display: flex;
		width: 256rpx;
		height: 60rpx;
		line-height: 60rpx;
		border: 2rpx solid #d8d8d8;
		border-radius: 10rpx;
		background: #ffffff;
	}

	.icon {
		box-sizing: border-box;
		width: 80rpx;
		text-align: center;
		font-size: 28rpx;

		&--hover {
			background-color: #E6E6E6;
		}

		&--bd-left {
			border-left: 2rpx solid #d8d8d8;
		}

		&--bd-right {
			border-right: 2rpx solid #d8d8d8;
		}
	}
</style>